import { createRouter, createWebHistory } from 'vue-router'
// createRouter 创建路由实例
// createWebHistory 创建history模式的路由
import Parent from '@/views/Layout/Parent.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // 配置path和components对应关系
  routes: [
    // 一级路由
    {
      path: '/',
      component: () => import('@/views/Layout/index.vue'),
      children: [
        // 二级路由
        {
          path: 'welcome',
          name: 'home',
          component: () => import('@/views/Home/index.vue'),
          meta: {
            title: '首页',
            icon: 'House'
          }
        },
        {
          path: 'manu1',
          name: 'manu1',
          component: Parent,
          meta: {
            title: '菜单',
            icon: 'Notification'
          },
          children: [
            {
              path: 'manu1-1',
              name: 'manu1-1',
              title: '菜单1-1',
              component: Parent,
              meta: {
                title: '菜单1-1',
                icon: 'Odometer'
              },
              children: [
                {
                  path: 'manu1-1-1',
                  name: 'manu1-1-1',
                  component: () => import('@/views/Manu1/index.vue'),
                  meta: {
                    title: '菜单1-1-1',
                    icon: 'Present'
                  }
                },
                {
                  path: 'manu1-1-2',
                  name: 'manu1-1-2',
                  component: () => import('@/views/Manu2/index.vue'),
                  meta: {
                    title: '菜单1-1-2',
                    icon: 'Suitcase'
                  }
                }
              ]
            },
            {
              path: 'manu12',
              name: 'manu12',
              component: () => import('@/views/Manu2/index.vue'),
              meta: {
                title: '菜单12',
                icon: 'Money'
              }
            }
          ]
        },
        {
          path: 'manu2',
          name: 'manu2',
          component: () => import('@/views/Manu2/index.vue'),
          meta: {
            title: '菜单2',
            icon: 'CollectionTag'
          }
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/Login/index.vue')
    }
  ],
  // 定制路由滚动行为,路由切换时滚动到顶部
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
